#-*-coding:utf-8-*-
#!/usr/bin/python 
#filename: post.py 

from PyQt4.QtGui import *
from PyQt4.QtCore import *
import sys
import ui_postgresql
import postgres



class TestDialog(QDialog,ui_postgresql.Ui_Dialog):
    def __init__(self,parent=None):
        super(TestDialog,self).__init__(parent)
        self.setupUi(self)
        self.setFixedSize(373,150)
        self.setWindowFlags(Qt.Dialog | Qt.WindowMaximizeButtonHint | Qt.WindowMinimizeButtonHint)
        # self.connect(self.btnInstall,SIGNAL("clicked()"),self.on_btnInstall_clicked)

    @pyqtSlot()
    def on_btnInstall_clicked(self):
        s = postgres.install()
        if s == 0:
            QMessageBox.information(self,u"提示",u"数据库安装成功！")
        if s == 1:
            QMessageBox.critical(self,u"提示",u"连接数据库失败！")
        if s == 2:
            QMessageBox.critical(self,u"提示",u'没有找到配置文件！')
        if s == 3:
            QMessageBox.critical(self,u"提示",u'数据库 "vpgis" 已经存在！')
        pass
     
    @pyqtSlot()
    def on_btnUninstall_clicked(self):
        reply = QMessageBox.question(self,u'提示',
                    u"删除数据库会导致数据丢失！\n你确定要删除吗？", QMessageBox.Yes,
                    QMessageBox.No)
        if reply == QMessageBox.Yes:
            s = postgres.uninstall()
            if s == 0:
                QMessageBox.information(self,u"提示",u"数据库卸载成功！")
            if s == 1:
                QMessageBox.critical(self,u"提示",u'数据库 "vpgis"不存在！')
            if s == 2:
                QMessageBox.critical(self,u"提示",u"删除数据库失败！")

app=QApplication(sys.argv)
trans = QTranslator()
trans.load(u":/ui/zh")
app.installTranslator(trans)
dialog=TestDialog()
dialog.show()
app.exec_()